rm(list = ls())

if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse, fixest)

# Load and filter data

dat <- readRDS("data/zij.rds") %>%
  filter(yob >= 1960 & yob <= 1975) %>%
  mutate_at(vars(one_of("DDR_kapitalismus", "vereinigung_dagegen", "DDR_reformsozial")), ~ . * 100) %>% ## outcomes in p.p.
  mutate(
    post = ifelse(yob >= 1971, 1, 0),
    indoctrination = yob * post,
    indoctrination = -indoctrination
  ) ## invert coefficient; see section A.3.2 for details


# Define outcomes

outcomes <- c("DDR_kapitalismus", "vereinigung_dagegen", "DDR_reformsozial")

# Estimate RKD model split by gender

m1 <- feols(.[outcomes] ~ yob + post + indoctrination,
  split = ~gender,
  data = dat
)

etable(list(m1),
  dict = c(
    "DDR_kapitalismus" = "Capitalism",
    "yob" = "Year of birth",
    "gender" = "Gender",
    "post" = "Post",
    "vereinigung_dagegen" = "Reunification",
    "DDR_reformsozial" = "Socialism"
  ),
  digits = 4,
  keep = "indoctrination",
  digits.stats = 3,
  fitstat = ~ r2 + n
)
